<?php

namespace Mem;

use MemLib\MemBase;
use MemLib\Pdb;

/**
 * 用户账号手机注册来源操作类
 *
 * @version 1.0
 * @author 张云江
 */
class MemOrder_Application_info extends MemBase
{
    public function __construct()
    {
        parent::__construct(Pdb::db_order, "t_order_application_info");
    }

    /**
     * 插入数据
     * @param mixed $build_id 应用build ID
     * @param mixed $version 当前版本号
     * @param mixed $min_version 最低版本号
     * @param mixed $is_show_ad 1.显示广告 0.不显示广告
     * @param mixed $ad_app_id 穿山甲 广告ID
     * @param mixed $ad_tail_id 穿山甲 开屏广告
     * @param mixed $ad_incentive_id 穿山甲 激励广告
     * @param mixed $ae_resource_url 视频编辑-AE模版接口
     * @param mixed $ae_materialtype_url 视频编辑-AE模版接口
     */
    public function insertDataWithParam($application_name, $application_type, $build_id, $version, $min_version, $is_show_ad, $ad_app_id, $ad_tail_id, $ad_incentive_id, $ae_resource_url, $ae_materialtype_url, $application_password, $environment)
    {
        $insert_dt = date("Y-m-d H:i:s", time());
        $data = array(
            "application_name" => $application_name,
            "application_type" => $application_type,
            "application_password" => $application_password,
            "build_id" => $build_id,
            "version" => $version,
            "min_version" => $min_version,
            "is_show_ad" => $is_show_ad,
            "ad_app_id" => $ad_app_id,
            "ad_tail_id" => $ad_tail_id,
            "ad_incentive_id" => $ad_incentive_id,
            "ae_resource_url" => $ae_resource_url,
            "ae_materialtype_url" => $ae_materialtype_url,
            "environment" => $environment,
            "is_delete" => 0,
            "insert_dt" => $insert_dt
        );
        $res = $this->addData($data);
        if ($res) {
            \Mlog::info("插入数据成功" . $build_id);
        }
        return $this->getTmpID();
    }

    /**
     * 获取应用详情
     * @param int $id
     * @return array
     */
    public function getInfoWithid($application_id)
    {
        $application_id = (int)$application_id;
        $sql = "SELECT * FROM t_order_application_info WHERE application_id='{$application_id}';";
        $data = $this->getData($sql, "getInfoWithid:{$application_id}");
        return $data ? $data[0] : array();
    }

    /**
     * 获取应用详情
     * @param int $id
     * @return array
     */
    public function getInfoWithbuild_id($build_id)
    {
        $sql = "SELECT * FROM t_order_application_info WHERE build_id='{$build_id}';";
        $data = $this->getData($sql, "getInfoWithbuild_id:{$build_id}");
        return $data ? $data[0] : array();
    }

    /**
     * 获取应用详情
     * @return array
     */
    public function getCountDataWithAll()
    {
        $sql = "SELECT COUNT(*) AS total FROM t_order_application_info WHERE is_delete=0;";
        $data = $this->getData($sql, "getCountDataWithAll");
        return empty($data) ? $data : $data[0]['total'];
    }

    /**
     * 获取应用详情
     * @return array
     */
    public function getDataWithAll()
    {
        $sql = "SELECT * FROM t_order_application_info WHERE is_delete=0;";
        $data = $this->getData($sql, "getDataWithAll");
        return $data;
    }

    /**
     * 获取应用详情
     * @return array
     */
    public function getDataWithAllADNPage($mempage)
    {
        $sql = "SELECT * FROM t_order_application_info WHERE is_delete=0 ORDER BY insert_dt DESC LIMIT {$mempage->getLimitIndex()},{$mempage->pagesize};";
        $data = $this->getData($sql, "getDataWithAllAllPage:{$mempage->getLimitIndex()}:pagesize:{$mempage->pagesize}");
        return $data;
    }
    /**
     * 获取应用详情
     * @return array
     */
    public function DeleteDataWithApplicationID($application_id)
    {
        $application_id = (int)$application_id;
        return $this->deleteData(array("application_id" => $application_id));
    }
    /**
     * 更新信息
     * @param $updata
     * @param $wheredata
     * @return bool
     */
    public function updateDataWithParam($updata, $wheredata)
    {
        if (empty($updata) || empty($wheredata)) {
            return false;
        }

        $updata = \MemLib\PublicFunc::convertToHtmlKeyVal($updata);
        $wheredata = \MemLib\PublicFunc::convertToHtmlKeyVal($wheredata);

        $ret = $this->updateData($updata, $wheredata);

        return $ret;
    }
}
